/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package load.logic;

import core.InPort;
import core.DispatcherPort;
import core.OutPort;
import core.StdNode;
import core.TriggerPort;
/**
 *
 * @author Ben
 */
public class For extends StdNode {
	private DispatcherPort bodyPort = new DispatcherPort();
        private DispatcherPort finished = new DispatcherPort();
        private int i;
	private TriggerPort argChanged = new TriggerPort() {
		@Override
		public void callInternal() {
			bodyPort.callTargets();
		}
	};
	private InPort begin = new InPort(Integer.class, argChanged);
	private InPort end = new InPort(Integer.class, argChanged);
        private InPort increment = new InPort(Integer.class, argChanged,1);

	private OutPort res = new OutPort(Integer.class)
	{
		@Override
		public Object getValueInternal() {
			return new Integer(i);
		}
	};
	private TriggerPort execute = new TriggerPort() {
		@Override
		public void callInternal() {
                        for(i = ((Integer)begin.getValue()).intValue();
                        i < ((Integer)end.getValue()).intValue(); 
                        i+=((Integer)increment.getValue()).intValue()){
				bodyPort.callTargets();
                        }
                        finished.callTargets();
		}
	};

	public For() {
		autoPutPorts();
	}
}